//第一种解法,不过太繁琐了
class Solution {
    public boolean CheckPermutation(String s1, String s2) {
        Map<Character,Integer> map1 = new HashMap<>();
        Map<Character,Integer> map2 = new HashMap<>();
        if(s1 != null){
            for(char ch : s1.toCharArray()){
                int count = map1.getOrDefault(ch,0) + 1;
                map1.put(ch,count);
            }
        }

        if(s2 != null){
            for(char ch : s2.toCharArray()){
                int count = map2.getOrDefault(ch,0) + 1;
                map2.put(ch,count);
            }
        }
        
        if(s1.length() == s2.length()){
            if(s1 == null) return true;
            for(char ch: s1.toCharArray()){
                if(map2.containsKey(ch)){
                    if(map1.get(ch).compareTo(map2.get(ch)) != 0){
                        return false;
                    }
                }else{
                    return false;
                }
            }
            return true;
        }else{
            return false;
        }
    }
}

//第二种,使用ASCII码,，应该囊括了所有的字符，直接上128即可。
class Solution {
    public boolean CheckPermutation(String s1, String s2) {
        int[] map = new int[128];
        for(int i = 0; i < s1.length(); i++)
            map[s1.charAt(i)]++;
        for(int j = 0; j < s2.length(); j++)
            map[s2.charAt(j)]--;
        for(int t: map)
            if(t != 0) return false;
        return true;
    }
}

//第三种 直接转换成数组进行排序然后转回来进行比较即可.
class Solution {
    public boolean CheckPermutation(String s1, String s2) {
        char[] ch1 = s1.toCharArray();
        char[] ch2 = s2.toCharArray();
        Arrays.sort(ch1);
        Arrays.sort(ch2);
        return new String(ch1).equals(new String(ch2));
    }
}